Page({
    data: {
        info: null,
        openChoose: false,
        peopleNum: 0, //推荐的人数
        // actions: [{
        //         name: '提现到微信',
        //         index: 0,
        //     },
        //     {
        //         name: '提现到银行卡',
        //         index: 1,
        //     },
        // ],
    },
    onLoad: function(options) {
        if (options.uid) { //绑定关系
            return this.redirect_login(options.uid)
        }
        this.getPeopleNum()
        let url = `/api/article/detail?article_id=12`
        this.request({
            url,
            loadingTip: '加载中',
            login: false
        }, res => {
            let article_content = res.data.article_content.content.replaceAll('<table>', '<table border="1px solid #000" cellspacing="0" cellpadding="6">')
            this.setData({ article_content })
        })
    },
    onShow() {
        this.getDetail() /**获取资金明细 */
        this.delay(() => {
            if (!this.data.userInfo) {
                //获取用户信息
                this.getUserInfo(() => {
                    this.data.userInfo.is_auth === 0 && this.getUserProfile() //没有授权过微信昵称头像时获取
                })
            }
        }, 100)
    },
    /**获取资金明细 */
    getDetail() {
        this.request({
            url: '/api/user/capital'
        }, res => {
            this.setData({ info: res.data })
        })
    },
    /**获取推荐人数 */
    getPeopleNum() {
        this.request({
            url: '/api/agent/invite',
            data: { limit: 1, type: 1 }
        }, res => {
            this.setData({ peopleNum: res.count })
        })
    },
    /**点击提现按钮 */
    withdrawal() {
        this.request({
            url: '/api/user/tixian',
            loadingTip: '加载中',
        }, res => {
            if (Number(res.data.award) <= 0) return wx.showToast({
                title: '可提现金额不足',
                icon: 'none',
                duration: 2000
            })
            this.setData({
                // openChoose: true,
                enableNum: res.data
            })
            wx.navigateTo({
                url: `/pages/withdrawal/index?type=0`,
                success: res => {
                    res.eventChannel.emit('acceptDataFromOpenerPage', { data: this.data.enableNum })
                }
            })
        })
    },
    // onClickChooseItem(event) { //0---提现至微信  1---提现至银行卡
    //     const { index } = event.detail;
    //     wx.navigateTo({
    //         url: `/pages/withdrawal/index?type=${index}`,
    //         success: res => {
    //             res.eventChannel.emit('acceptDataFromOpenerPage', { data: this.data.enableNum })
    //         }
    //     })
    //     this.setData({ openChoose: false })
    // },
    //点击分享
    onShareAppMessage() {
        let options = '/pages/promotion_center/index'
        if (this.data.userInfo) options += `?uid=${this.data.userInfo.uid}`
        return {
            path: options
        }
    }
})